Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

599
Visualizações
JS fetch() | How to hide console error on 404?

I'm using javascripts fetch() method to check if a file on the server exists, if not i want to fallback to fetching another default file. In this article I allready learned that JS does not throw an error if the request results in an 404 Error, but sets response.ok to false.

So my code looks like this now:

let resp;

resp = await fetch("url1"); //check for custom file at url1
if (!resp.ok) { resp = await fetch("url2"); } //if not found use default file at url2

It work's as expected, but: if the first request returns a 404-Status Code the console allways shows an error for the 404 Response. I dont want to see the Error in the console because it looks like an application error, but just means that the default file was loaded... Any Ideas how to fix this? I'm using Chrome and it looks like this:

Screenshot - error in Chrome's console

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda